﻿
<script type="text/javascript" src="Map.js"></script>
<script type="text/javascript" src="util/CalculateUtil.js"></script>

<script type="text/javascript" src="function/Year.js"></script>
<script type="text/javascript" src="function/Sum.js"></script>
<script type="text/javascript" src="function/If.js"></script>
<script type="text/javascript" src="function/FunctionLib.js"></script>

<script type="text/javascript" src="ExpressionParser.js"></script>
<script type="text/javascript" src="FormulaParser.js"></script>

<SCRIPT LANGUAGE="JavaScript">
<!--

String.prototype.trim = function(){
	return this.replace(/^\s*|\s*$/g,"");
}

var exp = "1+2";
//exp = "1+3+sum(3+45)+47";
//exp = "(year(2008-07-05)=2005)";
exp = "(0-1)+3";


exp = "-1+3";
exp = "3+(-1)";

exp = "if((1=1 && (2+1)=3),4)";
//exp = "if((1=2 && (2+1)=3),4);if((1=5 && (2+1)=3),3);3+4";//相当于:if(){}else if(){}else{}
//exp = "1000*(year()-year(2005-06-14))";


var test = new ExpressionParser();
var value = test.calculate(exp);
//alert(value);



var formulaStr = "({基本工资}+[档案工资])+[职级补贴]+([工龄补贴]+[学历补贴]+[职称补贴]+[独生子女补贴])-([养老保险]+[医疗保险]+[失业保险]+[公积金]+[个人所得税]+[工会费])+[补发工资]";
//formulaStr = "({基本工资}+{档案工资})+{职级补贴}";
//formulaStr = "如果 [学历]=大专 且 [学历]=本科 则 {档案工资}+10 如果 [学历]=本科1 则 {档案工资}+1 否则 1000+2000";
formulaStr = "如果 [学历]=大专 且 [学历]=本科 || 1=1 则 {档案工资}+10";

var map = new Map();
map.put("基本工资", "1000");map.put("档案工资", "100");
map.put("职级补贴", "11");
map.put("工龄补贴", "21");map.put("学历补贴", "22");map.put("职称补贴", "23");map.put("独生子女补贴", "24");
map.put("养老保险", "31");map.put("医疗保险", "32");map.put("失业保险", "33");map.put("公积金", "34");map.put("工会费", "36");//map.put("个人所得税", "35");
map.put("补发工资", "-41.242");

map.put("学历", "本科");

map.put("个人所得税", "-41.242");

var parser = new FormulaParser();
var value = parser.parseFormula(formulaStr,map);
alert("value = " + value);	
		
		
//var b = eval("'w'=='w' && 1>=2 || true ");
//alert(b);

//-->
</SCRIPT>